// mu0.C -- music0 and the calibrated Z
void a(vector<TH1 *> &v, TObject *h){ v.push_back((TH1F *)h); }
void mu0(){
  TFile *f = new TFile(getenv("TMP1"));
  TTree *etf = (TTree *)f->Get("etf");
  vector<TH1 *> v;
  TH1 *h;

  TCanvas *c = new TCanvas("c", "Amplitude related info - ADCs and QDCs", 1680, 1050);
  c->Divide(3, 3);
  c->cd(1); etf->Draw("mu0v[0]:mu0v[1]>>h1(500, 0., 5000., 500, 0., 5000.)", "", "colz");
  f->GetObject("h1", h); h->SetTitle("MUSIC0: Ch0 vs Ch1");
  h->GetXaxis()->SetTitle("Ch0"); h->GetYaxis()->SetTitle("Ch1");
  c->cd(2); etf->Draw("mu0v[2]:mu0v[3]>>h2(500, 0., 5000., 500, 0., 5000.)", "", "colz");
  f->GetObject("h2", h); h->SetTitle("MUSIC0: Ch2 vs Ch3");
  h->GetXaxis()->SetTitle("Ch2"); h->GetYaxis()->SetTitle("Ch3");
  c->cd(3); etf->Draw("mu0>>h3(500, 0., 5.)");
  f->GetObject("h3", h); h->SetTitle("MUSIC0: (1+2+3+4)/1000.");
  c->cd(4); etf->Draw("mu0:atof1>>h4(500, 110., 180., 500, 0., 5.)", "atof1 > 0.", "colz");
  f->GetObject("h4", h); h->SetTitle("MUSIC0 vs tof1 (T0->T1)");
  h->GetXaxis()->SetTitle("tof1 [ns]"); h->GetYaxis()->SetTitle("mu0 arb.");
  c->cd(5); etf->Draw("az0:dcTaU1_wireHitPos[1]"
    ">>h5(36, -45., 45., 500, 10., 45.)", "dcTaU1_wireHitPos[1]!=-999.", "colz");
  f->GetObject("h5", h); h->SetTitle("MUSIC0 vs Hit Y (DCTaU1-Y)");
  h->GetXaxis()->SetTitle("DCTaU1 Y [mm]"); h->GetYaxis()->SetTitle("mu0 arb.");
  c->cd(6); etf->Draw("mu0:dcTaU0_wireHitPos[0]>>h6(36, -45., 45., 500, 0., 5.)",
    "dcTaU0_wireHitPos[1]!=-999.", "colz");
  f->GetObject("h6", h); h->SetTitle("MUSIC0 vs Hit X (DCTaU0-X)");
  h->GetXaxis()->SetTitle("DCTaU0 X [mm]"); h->GetYaxis()->SetTitle("mu0 arb.");
  // az0= // dec2023
  //  sqrt(mu0*exp(0.0017*(pdcTaWire[0][1][1]+30.))/(0.00228*pow(atof1-121.43353,2)+6.973))*63.3748-1.22128
  c->cd(7); etf->Draw("az0>>h7(500, 0., 40.)", "az0>0.");
  c->cd(8); etf->Draw("az0:tstop.q()>>h8(500, 0., 5000., 500, 0., 40.)",
    "az0>0.&&tstop.fired()==4", "colz");
  f->GetObject("h8", h); h->SetTitle("Z0 vs T1-QDC");
  h->GetXaxis()->SetTitle("T1 QDC"); h->GetYaxis()->SetTitle("Z0");

  // the calibration
  c->cd(9);
  // etf->Draw("mu0*exp(0.0025*(dcTaU1_wireHitPos[1]+30.):dcTaU1_wireHitPos[1]>>h9(36, -45., 45., 500, 0., 4.3)", "dcTaU1_wireHitPos[1]!=-999.", "colz");
  // etf->Draw("sqrt(mu0*exp(0.0025*(dcTaU1_wireHitPos[1]+30.))/(0.0023*pow(tof1-121.,2)+7.))*61.9468-2.44614:atof1>>h9(1000, 135., 160., 1000, 10., 45.)", "dcTaU1_wireHitPos[1]!=-999.&&atof1>0.", "colz");
  etf->Draw("az0:atof1>>h9(1000, 125., 160., 1000, 10., 45.)",
    "dcTaU1_wireHitPos[1]!=-999.&&atof1>0.", "colz");
  f->GetObject("h9", h); h->SetTitle("Z0 vs tof1");
  h->GetXaxis()->SetTitle("TOF1 [ns]"); h->GetYaxis()->SetTitle("Z0");

  c->Print("mu0.pdf");
} // end function amp
